from ResponseCode import ResponseCode


class CommonResponse:
    def __init__(self, code, message=None, data=None, latexDate=None):
        self.code = code
        self.message = message
        self.data = data
        self.latexDate = latexDate

    @staticmethod
    def isSuccess(self):
        return self.code == ResponseCode.SUCCESS.getCode()

    @staticmethod
    def createForSuccess(message=None, data=None, latexData=None):
        if message is None:
            message = ResponseCode.SUCCESS.getDesc()
        if data is None and latexData is None:
            return CommonResponse(ResponseCode.SUCCESS.getCode(), message)
        elif data is not None and latexData is None:
            return CommonResponse(ResponseCode.SUCCESS.getCode(), message, data)
        elif data is not None and latexData is not None:
            return CommonResponse(ResponseCode.SUCCESS.getCode(), message, data, latexData)
        else:
            raise ValueError("Invalid arguments")

    @staticmethod
    def createForSuccessMessage(message):
        return CommonResponse(ResponseCode.SUCCESS.getCode(), message)

    @staticmethod
    def createForError(message, code=None):
        if code is None:
            code = ResponseCode.ERROR.getCode()
        return CommonResponse(code, message)

    @staticmethod
    def createForErrorMessage(message):
        return CommonResponse(ResponseCode.ERROR.getCode(), message)

    @staticmethod
    def createForErrorData(data):
        return CommonResponse(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDesc(), data)



